import axios from 'axios'
import { baseURL } from '../configFile'
import DataType from "../types/DataType";
import DataCategory from "../types/DataCategory";

const axiosReq = axios.create({
    baseURL
})

//添加数据类型
export const addDataCategory = (dataCategoryName: string, dataType: DataType, selectList?: Array<string>) => {
    return axiosReq.post('/addDataCategory', { dataCategoryName, dataType, selectList })
}

//删除数据类型
export const deleteDataCategory = (dataCategoryID: number) => {
    return axiosReq.post('/deleteDataCategory', { 'dataCategoryID': dataCategoryID })
}

//分页列出数据类型
export const listDataCategory = (offset: number, limit: number) => {
    return axiosReq.get('/listDataCategory', { params: { offset, limit } })
}

//分页列出已删除的全部数据类型
export const listDeletedCategory = (offset: number, limit: number) => {
    return axiosReq.get('/listDeletedCategory', { params: { offset, limit } })
}

//查询全部数据类型数量
export const queryCategoryAmount = () => {
    return axiosReq.get('/queryCategoryAmount')
}

//查询全部已删除数据类型数量
export const queryDeletedCategoryAmount = () => {
    return axiosReq.get('/queryDeletedCategoryAmount')
}

//搜索特定数据类型
export const searchCategory = (keyword: string) => {
    return axiosReq.get('/searchCategory', { params: { keyword } })
}

//搜索特定数据类型（已删除）
export const searchDeletedCategory = (keyword: string) => {
    return axiosReq.get('./searchDeletedCategory', { params: { 'keyword': keyword } })
}

//恢复被删除的数据类型
export const deletedDataCategoryRecover = (dataCategoryID: number) => {
    return axiosReq.post('/deletedDataCategoryRecover', { 'dataCategoryID': dataCategoryID })
}

//查询特定数据类型
export const queryCategory = (categoryID: number) => {
    return axiosReq.get('./queryCategory', { params: { 'categoryID': categoryID } })
}

//修改数据类型
export const modifyDataCategory = (dataCategory: Pick<DataCategory, 'dataCategoryID'> & Partial<Pick<DataCategory, 'dataCategoryName'>>, selectList?: Array<string>) => {
    return axiosReq.post('./modifyDataCategory',  {...dataCategory, selectList} )
}

//查询可选项
export const queryCategoryOptions = (categoryID: number) => {
    return axiosReq.get('/queryCategoryOptions', { params: { 'categoryID': categoryID } })
}